package com.fzy.core.converters;

import java.lang.reflect.Member;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import ognl.DefaultTypeConverter;
import com.opensymphony.webwork.util.WebWorkTypeConverter;
import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.util.XWorkConverter;

public class MyDateConverter extends WebWorkTypeConverter {

	private static final SimpleDateFormat sdf = new SimpleDateFormat(
			"yyyy-MM-dd");

	public Object convertFromString(Map context, String[] values, Class toClass) {
		Date result = null;
		try {
			if(values != null && values.length > 0)
				result = sdf.parse(values[0]);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return result;
	}

	public String convertToString(Map context, Object o) {
		String result = null;
		result = sdf.format((Date)o);
		return result;
	}
}
